package com.paic.mhis.hcpms.assessment.biz.service.impl;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.paic.mhis.common.base.intergration.dao.CommonDAO;
import com.paic.mhis.hcpms.assessment.biz.service.WebSpiderService;
import com.paic.mhis.hcpms.assessment.dto.SecondLevelIndicatorDto;
import com.paic.mhis.hcpms.assessment.util.AssessmentUtils;

/**
 * @author EX-ZENGYUANCHAO001
 * 
 */
@Service("WebSpiderService")
public class WebSpiderServiceImpl implements WebSpiderService {

	@Autowired
	private CommonDAO commonDAO;

	private static final Log LOG = LogFactory.getLog(WebSpiderServiceImpl.class);

	@Override
	public List<ArrayList<SecondLevelIndicatorDto>> findLevel2IndictorList(String healthcareProviderCode, String date,
			String structureNo, String regionCode, String hosGrade) {
		List<ArrayList<SecondLevelIndicatorDto>> indicatorList = new ArrayList<ArrayList<SecondLevelIndicatorDto>>();

		Map<String, String> lastParam = new HashMap<String, String>();
		Map<String, String> currentParam = new HashMap<String, String>();
		Map<String, String> avgParam = new HashMap<String, String>();

		try {
			lastParam.put("healthcareProviderCode", healthcareProviderCode);
			lastParam.put("date", AssessmentUtils.getLastMonth(date, "yyyy-MM"));
			lastParam.put("structureNo", structureNo);
			currentParam.put("healthcareProviderCode", healthcareProviderCode);
			currentParam.put("date", date);
			currentParam.put("structureNo", structureNo);
			avgParam.put("date", date);
			avgParam.put("structureNo", structureNo);
			avgParam.put("hosGrade", hosGrade);
			avgParam.put("regionCode", regionCode);

			@SuppressWarnings("unchecked")
			List<SecondLevelIndicatorDto> currentSiDtoList = (ArrayList<SecondLevelIndicatorDto>) commonDAO.query(
					"assessmentDao.getLevel2Indicator", currentParam);
			@SuppressWarnings("unchecked")
			List<SecondLevelIndicatorDto> avgSiDtoList = (ArrayList<SecondLevelIndicatorDto>) commonDAO.query(
					"assessmentDao.getAvgLevel2Indicator", avgParam);
			@SuppressWarnings("unchecked")
			List<SecondLevelIndicatorDto> lastSiDtoList = (ArrayList<SecondLevelIndicatorDto>) commonDAO.query(
					"assessmentDao.getLevel2Indicator", lastParam);

			indicatorList.add((ArrayList<SecondLevelIndicatorDto>) lastSiDtoList);
			indicatorList.add((ArrayList<SecondLevelIndicatorDto>) currentSiDtoList);
			indicatorList.add((ArrayList<SecondLevelIndicatorDto>) avgSiDtoList);
		} catch (ParseException e) {
			LOG.info("--日期转换异常--");
			LOG.error(e, e);
		}
		return indicatorList;
	}

}
